package com.heima.wemedia.baidu;

import com.heima.utils.baidu.HttpUtil;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.net.URLEncoder;

/**
 * @author xiaquanen
 * @version 1.0
 * @project heima-leadnews
 * @date 2024/7/23 09:49:36
 */

    /**
     * 文本审核接口
     */
    public class TextCensor {

        /**
         * 重要提示代码中所需工具类
         * FileUtil,Base64Util,HttpUtil,GsonUtils请从
         * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
         * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
         * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
         * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
         * 下载
         */
        public static String TextCensor() {
            // 请求url
            String url = "https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined";
            try {
                String param = "text=" + URLEncoder.encode("ssbsbsbsbsbsbsb", "utf-8");

                // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
                String accessToken = "24.d98d9136d61c3b34123ca66dd9fbf7cb.2592000.1724291641.282335-97737307";

                String result = HttpUtil.post(url, accessToken, param);
                System.out.println(result);
                return result;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public static void main(String[] args) {
            TextCensor.TextCensor();
        }
    }
